if ( SERVER ) then
	AddCSLuaFile( "shared.lua" )
	AddCSLuaFile( "cl_init.lua" )
	SWEP.HoldType			= "rpg"
end

if ( CLIENT ) then

	SWEP.Category 		= "HL2 Beta Sweps"
	SWEP.PrintName		= "Rocket Launcher"
	SWEP.Author		= "Valve"
	SWEP.Contact		= "N/A"
	SWEP.Purpose		= "Shooting Rockets"
	SWEP.ViewModelFOV	= "70" 
	SWEP.Instructions	= "Primary=Shoot Rockets"
	SWEP.Slot		= 5
	SWEP.Slotpos 		= 0
	SWEP.CSMuzzleFlashes	= true
end

SWEP.data = {}
SWEP.data.newclip			= false

SWEP.Spawnable			= false
SWEP.AdminSpawnable		= true

SWEP.ViewModel			= "models/weapons/v_rpk.mdl"
SWEP.WorldModel			= "models/Weapons/w_ml.mdl"
SWEP.ViewModelFlip		= false

SWEP.Primary.Sound		= Sound( "weapons/rocket_fire.wav" )
SWEP.Primary.Recoil		= 0.2
SWEP.Primary.Damage		= 19
SWEP.Primary.NumShots		= 1
SWEP.Primary.Cone		= 0.01
SWEP.Primary.ClipSize		= 1
SWEP.Primary.Delay		= 1
SWEP.Primary.DefaultClip	= 4
SWEP.Primary.Automatic		= false
SWEP.Primary.Ammo		= "RPG_Round"

SWEP.Secondary.ClipSize		= -1
SWEP.Secondary.DefaultClip	= -1
SWEP.Secondary.Automatic	= false
SWEP.Secondary.Ammo		= "none"
Zoom = 0

function SWEP:Initialize()
	if (SERVER) then
		self:SetWeaponHoldType(self.HoldType)
	end
end

function SWEP:SecondaryAttack()
	if(Zoom == 0) then
		if(SERVER) then
			self.Owner:SetFOV( 35, 0.30 )
		end
		self:EmitSound("Weapon_AR2.Special1")
                Zoom = 1
	else
		if(SERVER) then
			self.Owner:SetFOV( 0, 0.30 )
		end
		self:EmitSound("Weapon_AR2.Special2")
                Zoom = 0
	end
end

function SWEP:PrimaryAttack()

	if ( !self:CanPrimaryAttack() ) then return end

	self.Weapon:EmitSound(self.Primary.Sound)

	self:TakePrimaryAmmo( self.Primary.NumShots )

	self:TakePrimaryAmmo( 0 )
	self.Owner:ViewPunch( Angle( -1.00, 0, 0 ) )
	self.Weapon:SetNextPrimaryFire( CurTime() + self.Primary.Delay )

	local shotpos = self.Owner:GetShootPos()
	shotpos = shotpos + self.Owner:GetForward() * 0
	shotpos = shotpos + self.Owner:GetRight() * 10
	shotpos = shotpos + self.Owner:GetUp() * -5

	if (SERVER) then
			
		local rocket = ents.Create("ent_rocket_fire")
		if (ValidEntity(rocket)) then
			rocket:SetPos(shotpos)
			rocket:SetOwner(self.Owner)
 			rocket:Spawn()
			rocket.Owner = self.Owner
			rocket:ActivateRocket()
		end

		local Trail = ents.Create("env_rockettrail")
		Trail:SetPos(rocket:GetPos() - 16*rocket:GetForward())
		Trail:SetParent(rocket)
		Trail:SetLocalAngles(Vector(0,0,0))
		Trail:SetKeyValue("scale", "0.2")
		Trail:Spawn()

		local b = ents.Create( "info_target" )
		if (ValidEntity(b)) then
			b:SetPos( self.Owner:GetEyeTrace( ).HitPos + Vector(0,0,0))
			b:Spawn( )
			rocket:PointAtEntity( b )
			b:Remove( )
		end
	end
        
	self.Weapon:SendWeaponAnim( ACT_VM_PRIMARYATTACK )
	self.Owner:MuzzleFlash()
	self.Owner:SetAnimation( PLAYER_ATTACK1 )
end

function SWEP:Reload()
	if self.Owner:GetActiveWeapon():Clip1() == self.Primary.ClipSize then return end
	if self.Reloading || self.Owner:GetAmmoCount( "RPG_Round" ) == 0 then return end
	if self.Weapon:Clip1() < self.Primary.ClipSize then
		self.data.oldclip = self.Weapon:Clip1()
		self.Weapon:EmitSound(Sound("weapons/rpg/rpg_reload.wav"))
		self.Weapon:DefaultReload(ACT_VM_RELOAD)
		self.data.newclip = 1
	end
end

function SWEP:Deploy()
	--self.Weapon:EmitSound(Sound("weapons/pistol_ready.wav"))
       self.Weapon( ACT_VM_DRAW ) 
end